<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('文章管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>文章标题：</p>
                                <input type="text" name="title"/>
                            </li>
                            <li>
                                文章专区：<select name="articleRegion" th:with="type=${@dict.getType('article_region')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>
                            <li>
                                <div class="form-group" style="width: 265px;">
                                    <label class="control-label">栏目分类：</label>
                                    <div class="input-group">
                                        <input id="treeId" name="categoryId" type="hidden"/>
                                        <input class="form-control" type="text" onclick="selectCategoryTree()" id="treeName" readonly="true">
                                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                                    </div>
                                </div>
                            </li>
                            <li>
                                审核状态：<select name="available" th:with="type=${@dict.getType('sys_available_status')}">
                                            <option value="">所有</option>
                                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                          </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="cms:article:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="cms:article:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="cms:article:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a onclick="publishArticles()" class="btn btn-outline btn-danger"><i class="fa fa-upload"></i>&nbsp;批量发布</a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">

        var articleModelDatas = [[${@dict.getType('article_model')}]];
        var articleRegionDatas = [[${@dict.getType('article_region')}]];
        var articleStatusDatas = [[${@dict.getType('sys_available_status')}]];

        var editFlag = [[${@permission.hasPermi('cms:article:edit')}]];
        var removeFlag = [[${@permission.hasPermi('cms:article:remove')}]];
        var prefix = ctx + "cms/article";


        var beforePreView=function(v){
            if(isNotEmpty(v)){
                var b=Fast.isExist(v);
                if(b){
                    return true;
                }
            }
            Fast.msg_error("页面不存在!");
            return false;
        }
        function list(){
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "createTime",
                sortOrder: "desc",
                modalName: "文章",
                columns: [{checkbox: true},
                    {field: 'id',title : '主键，文章ID',visible: false},
                    {field: 'articleRegion',title : '专区',visible:false,formatter: function(value, row, index) {
                            return $.table.selectDictLabel(articleRegionDatas, value);
                        }},
                    {field: 'author',title : '作者',visible:false},
                    {field: 'title',title : '文章标题',sortable:true},
                    {field: 'keywords',title : '关键词',visible:false},
                    {field: 'description',title : '摘要',visible:false},
                    {field: 'coverImage',title : '封面图片',visible:false,formatter: function(value, row, index) {
                        return value ? '<img src="'+ctx+value+'" style="max-width: 50px;max-height: 50px;"/>' : '';
                    }},
                    {field: 'articleModel',title : '文章模型',visible:false,formatter: function(value, row, index) {
                            return $.table.selectDictLabel(articleModelDatas, value);
                        }},
                    {field: 'category.categoryName',title : '栏目分类'},
                    {field: 'copyFlag',title : '转载标志',visible:false,formatter:function(v){
                        return 0 == v ? '否' : '是';
                    }},
                    {field: 'createTime',title : '创建时间',sortable:true},
                    {field: 'publishTime',title : '发布时间',sortable:true},
                    {field: 'link',title : '原始链接',visible:false},
                    {field: 'staticUrl',title:'静态页面',align:'center',width:"100px",visible:false,formatter:function(v,row){
                            if(isNotEmpty(v)){
                                return '<a class="btn btn-success btn-xs" href="'+v+'" onclick="return beforePreView(this.href)"><i class="fa fa-eye"></i>查看</a>';
                            }else{
                                return "-";
                            }
                        }
                    },
                    {field: '操作',title:'动态页面',align:'center',width:"100px",visible:false,formatter:function(v,row){
                            return '<a class="btn btn-success btn-xs" href="'+prefix+'/detail/'+row.id+'" target=\'_blank\'><i class="fa fa-eye"></i>查看</a>';
                        }
                    },
                    {field: 'tags_name',title : '标签',visible:false},
                    {field: 'hit',title : '点击数',align:'center',width:"80px",visible:false},
                    {field: 'available',title:'状态',align:'center',width:"100px",sortable:true,formatter:function(v){
                            return $.table.selectDictLabel(articleStatusDatas, v);
                        }
                    },
                    {title: '操作', align: 'center',width:"115px", formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        }
        $(function() {
            list();
        });


        /*栏目分类选择*/
        function selectCategoryTree() {
            var prefixTemp = ctx + "cms/category"
            var options = {
                title: '栏目分类选择',
                width: "380",
                url: prefixTemp + "/selectCategoryTree/" + $("#treeId").val(),
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var body = parent.layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            parent.layer.close(index);
        }

        var publishArticles=function(){
            var selecRow = $("#bootstrap-table").bootstrapTable('getSelections');
            if(selecRow.length > 0){
                Fast.confirm("确定批量发布文章吗？", function(){
                    var ids = new Array();
                    for(var i=0;i<selecRow.length;i++){
                        ids[ids.length] = selecRow[i]["id"]
                    }
                    $.ajax({
                        type:"post",
                        url: ctx + 'cms/article/batchPublish/'+ids,
                        data:null,
                        success:function(data,textStatus){
                            Fast.msg_success(data.msg);
                            $.table.search();
                        }
                    });
                });
            }else{
                Fast.msg_warning("请选择要发布的文章!");
            }
        }

    </script>
</body>
</html>
